package user

import (
	"context"
	"github.com/jinzhu/copier"
	apiAuth "navi-mumbai/app/api/admin/internal/auth"
	"navi-mumbai/app/rpc/usercenter/pb"
	"navi-mumbai/common/ctxdata"
	"navi-mumbai/common/xerr"

	"navi-mumbai/app/api/admin/internal/svc"
	"navi-mumbai/app/api/admin/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateMarqueeConfigLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdateMarqueeConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateMarqueeConfigLogic {
	return &UpdateMarqueeConfigLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateMarqueeConfigLogic) UpdateMarqueeConfig(req *types.UpdateMarqueeConfigReq) (resp *types.UpdateMarqueeConfigResp, err error) {
	// verify permission level
	adminUid := ctxdata.GetUidFromCtx(l.ctx)
	level := ctxdata.GetAdminPermissionLevelFromCtx(l.ctx)
	if !l.svcCtx.Auth.VerifyPermissionLevel(l.ctx, apiAuth.AdminUpdateMarqueeConfigApi, adminUid, level) {
		return nil, xerr.NewGrpcErrCodeMsg(xerr.AuthFail, "permission denied")
	}
	var in pb.UpdateMarqueeConfigReq
	_ = copier.Copy(&in, req)
	var rsp *pb.UpdateMarqueeConfigResp
	rsp, err = l.svcCtx.UcAdminRpc.UpdateMarqueeConfig(l.ctx, &in)
	if err != nil {
		return nil, err
	}
	resp = &types.UpdateMarqueeConfigResp{RetCode: 1}
	_ = copier.Copy(resp, rsp)
	return
}
